﻿// /*
//  * @Author: wanyiming
//  * @Date:2024-05-21-22:28
//  * @Description:
//  */

using Code.GameLogic.BaseClass;
using UnityEngine;

namespace Code.GameLogic.Map.Controller
{
    public class BlockController:AbsGameLogicController<BlockBo,MapManager>
    {
        //-----设置
        public float blockSize = 1f; //地板大小30px
        public float blockSpace = 0.3f; //地板大小30px
        private SpriteRenderer _frameSpriteRenderer;
        
        
        public void Start()
        {

        }


        public override void InitGo(BlockBo monsterBo)
        {
            BoxCollider2D boxCollider2D = gameObject.AddComponent<BoxCollider2D>();
            boxCollider2D.size = new Vector2(0.25f, 0.25f);
            var spriteRenderer = gameObject.AddComponent<SpriteRenderer>();
            spriteRenderer.sprite = Resources.Load<Sprite>("地图/地块/"+monsterBo.Type);
            // 可选：为图像设置位置、旋转和缩放
            gameObject.transform.rotation = Quaternion.identity; // 设置旋转
            var transform1 = transform;
            transform1.position = new Vector3(monsterBo.X*blockSpace, monsterBo.Y*blockSpace, 0); // 设置位置
            transform1.localScale = new Vector3(blockSize, blockSize, 1); // 设置缩放
            // 初始化网格边框
            InitFrame();
        }


        private void InitFrame()
        {
            GameObject frame = new GameObject("边框");
            frame.transform.parent = gameObject.transform;
            frame.transform.localPosition = Vector3.zero;
            _frameSpriteRenderer = frame.AddComponent<SpriteRenderer>();
            _frameSpriteRenderer.sprite = Resources.Load<Sprite>("地图/地块/边框");
            _frameSpriteRenderer.sortingOrder = -1;
        }

        
        
        public override void Watch()
        {
            _frameSpriteRenderer.sortingOrder = 1;
        }

        public override void Ignore()
        {
            _frameSpriteRenderer.sortingOrder = -1;
        }


        public void Update()
        {
            IsWatch();
        }
        
        public bool IsBlack()
        {
            return gameObject.transform.childCount == 2;
        }

        public bool IsType(int type)
        {
            return bo.Type == type;
        }



    }
}